﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HRProject.Code.DAO;
using HRProject.Code.Common;
using HRProject.Code.DTO;
using System.Collections.Generic;

namespace HRProject.User
{
    public partial class EditRecordType : System.Web.UI.Page
    {
        private Guid recordTypeId = Guid.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            string recordTypeIdStr = Request.Params["id"];
            try
            {
                recordTypeId = new Guid(recordTypeIdStr);
            }
            catch (Exception exp)
            {
                Console.Out.Write(exp.StackTrace);
                recordTypeId = Guid.Empty;
            }
            if (!IsPostBack)
            {
                RecordTypeDAO dao = new RecordTypeDAO();
                BLRecordType filter = new BLRecordType();
                filter.Id = recordTypeId;
                filter.Name=string.Empty;
                List<BLRecordType> recordTypes = dao.Search(filter);
                if (recordTypes.Count > 0)
                {
                    tbxName.Text = recordTypes[0].Name;
                    tbxDescription.Text = recordTypes[0].Description;
                }
            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if (!BLAuthentication.IsEditAllowed)
            {
                lblError.Text = ContentProvider.GetMessage("NotAuthorized");
                return;
            }

            BLRecordType recordType = new BLRecordType();
            recordType.Id = recordTypeId;
            recordType.Name = tbxName.Text.Trim();
            recordType.Description = tbxDescription.Text.Trim();
            recordType.DataSignature = 0;

            RecordTypeDAO dao = new RecordTypeDAO();
            dao.update(recordType);
            Util.CloseFrame(Response);
        }
    }
}
